﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    public class clsSanPhamHoanThanh
    {
        private string mDienGiai = "";
        private string mKhoaBoPhan = "";
        private string mKhoaDonVi = "";
        private string mKhoaHopDong = "";
        private string mKhoaSanPham = "";
        private string mKhoaTaiKhoanCo = "";
        private string mKhoaTaiKhoanNo = "";
        private string mNamThang = "";
        private double mSoDuBanDau = 0.0;
        private double mSoKetChuyen = 0.0;
        private double mTyLeHoanThanh = 0.0;

        public void ClearTemp(string pNamThang)
        {
            string commandText = " DELETE FROM GL_SanPhamHoanThanhTmp WHERE NamThang = '" + pNamThang + "'";
            DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
        }

        public bool Exists(string pNamThang)
        {
            string commandText = " SELECT TOP 1 NamThang FROM GL_SanPhamHoanThanh WHERE NamThang = '" + pNamThang + "' AND KhoaDonVi = '" + modGeneral.H_CLIENT + "'";
            return (LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(DBHelper.ExecuteScalar(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0])), "", modGeneral.TypeOfValue.Nothing).ToString().Trim() != "");
        }

        public DataTable GetDanhSachSanPhamDoDang()
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[4];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, this.mNamThang);
                commandParameters[2] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                commandParameters[3] = DBHelper.createParameter("@Task", DbType.Double, ParameterDirection.Input, 2);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_sp_GetSanPhamHoanThanh", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetSanPhamDoDang()
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[4];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, this.mNamThang);
                commandParameters[2] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                commandParameters[3] = DBHelper.createParameter("@Task", DbType.Double, ParameterDirection.Input, 1);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_sp_GetSanPhamHoanThanh", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetSanPhamHoanThanh(string pNamThang)
        {
            string commandText = "SELECT HT.KhoaTaiKhoanNo, TKN.SoTaiKhoan As TaiKhoanNo, HT.KhoaTaiKhoanCo, TKC.SoTaiKhoan As TaiKhoanCo, HT.KhoaBoPhan,  BP.TenViet As BoPhan, HT.KhoaSanPham, SP.TenViet As SanPham, HT.KhoaHopDong, HD.SoHopDong As HopDong,  HT.SoDuBanDau, HT.TyLeHoanThanh, HT.SoKetChuyen, HT.DienGiai  FROM GL_SanPhamHoanThanh HT  LEFT JOIN DM_TaiKhoan TKN ON HT.KhoaTaiKhoanNo = TKN.Khoa  LEFT JOIN DM_TaiKhoan TKC ON HT.KhoaTaiKhoanCo = TKC.Khoa  LEFT JOIN DM_DonViBoPhan BP ON HT.KhoaBoPhan = BP.Khoa  LEFT JOIN DM_SanPhamCongViec SP ON HT.KhoaSanPham = SP.Khoa  LEFT JOIN DM_HopDong HD ON HT.KhoaHopDong = HD.Khoa  WHERE HT.NamThang = '" + pNamThang + "' AND HT.KhoaDonVi = '" + modGeneral.H_CLIENT + "'";
            return DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
        }

        public bool GhiSo(string pKhoaChungTu, string pSoChungTu, string pNgayChungTu, string strTask)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[7];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, this.mNamThang);
                commandParameters[1] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                commandParameters[2] = DBHelper.createParameter("@KhoaChungTu", DbType.Int64, ParameterDirection.Input, pKhoaChungTu);
                commandParameters[3] = DBHelper.createParameter("@SoChungTu", DbType.Int64, ParameterDirection.Input, pSoChungTu);
                commandParameters[4] = DBHelper.createParameter("@NgayChungTu", DbType.Int64, ParameterDirection.Input, pNgayChungTu);
                commandParameters[5] = DBHelper.createParameter("@Task", DbType.Int64, ParameterDirection.Input, strTask);
                commandParameters[6] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_sp_GhiSoSanPhamHoanThanh", commandParameters);
                flag = Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(commandParameters[6].Value, 0, false);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Save()
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[11];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, this.mNamThang);
                commandParameters[1] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                commandParameters[2] = DBHelper.createParameter("@KhoaTaiKhoanNo", DbType.Int64, ParameterDirection.Input, this.mKhoaTaiKhoanNo);
                commandParameters[3] = DBHelper.createParameter("@KhoaTaiKhoanCo", DbType.Int64, ParameterDirection.Input, this.mKhoaTaiKhoanCo);
                commandParameters[4] = DBHelper.createParameter("@KhoaBoPhan", DbType.Int64, ParameterDirection.Input, this.mKhoaBoPhan);
                commandParameters[5] = DBHelper.createParameter("@KhoaSanPham", DbType.Int64, ParameterDirection.Input, this.mKhoaSanPham);
                commandParameters[6] = DBHelper.createParameter("@KhoaHopDong", DbType.Int64, ParameterDirection.Input, this.mKhoaHopDong);
                commandParameters[7] = DBHelper.createParameter("@SoDuBanDau", DbType.Date, ParameterDirection.Input, this.mSoDuBanDau);
                commandParameters[8] = DBHelper.createParameter("@TyLeHoanThanh", DbType.Date, ParameterDirection.Input, this.mTyLeHoanThanh);
                commandParameters[9] = DBHelper.createParameter("@SoKetChuyen", DbType.Date, ParameterDirection.Input, this.mSoKetChuyen);
                commandParameters[10] = DBHelper.createParameter("@DienGiai", DbType.Int64, ParameterDirection.Input, this.mDienGiai);
                flag = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "GL_sp_SanPhamHoanThanhTmp", commandParameters) > 0;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public string DienGiai
        {
            get
            {
                return this.mDienGiai;
            }
            set
            {
                this.mDienGiai = value;
            }
        }

        public string KhoaBoPhan
        {
            get
            {
                return this.mKhoaBoPhan;
            }
            set
            {
                this.mKhoaBoPhan = value;
            }
        }

        public string KhoaDonVi
        {
            get
            {
                return this.mKhoaDonVi;
            }
            set
            {
                this.mKhoaDonVi = value;
            }
        }

        public string KhoaHopDong
        {
            get
            {
                return this.mKhoaHopDong;
            }
            set
            {
                this.mKhoaHopDong = value;
            }
        }

        public string KhoaSanPham
        {
            get
            {
                return this.mKhoaSanPham;
            }
            set
            {
                this.mKhoaSanPham = value;
            }
        }

        public string KhoaTaiKhoanCo
        {
            get
            {
                return this.mKhoaTaiKhoanCo;
            }
            set
            {
                this.mKhoaTaiKhoanCo = value;
            }
        }

        public string KhoaTaiKhoanNo
        {
            get
            {
                return this.mKhoaTaiKhoanNo;
            }
            set
            {
                this.mKhoaTaiKhoanNo = value;
            }
        }

        public string NamThang
        {
            get
            {
                return this.mNamThang;
            }
            set
            {
                this.mNamThang = value;
            }
        }

        public double SoDuBanDau
        {
            get
            {
                return this.mSoDuBanDau;
            }
            set
            {
                this.mSoDuBanDau = value;
            }
        }

        public double SoKetChuyen
        {
            get
            {
                return this.mSoKetChuyen;
            }
            set
            {
                this.mSoKetChuyen = value;
            }
        }

        public double TyLeHoanThanh
        {
            get
            {
                return this.mTyLeHoanThanh;
            }
            set
            {
                this.mTyLeHoanThanh = value;
            }
        }
    }
}

